import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  {
    path: '/sys',
    component: Layout,
    name: 'sys',
    meta: { title: '系统管理', icon: 'el-icon-user' },
    children: [
      {
        path: 'user_info',
        name: 'user_info',
        component: () => import('@/views/user/user_info'),
        meta: { title: '用户管理' }
      },
      {
        path: 'dic_info',
        name: 'dic_info',
        component: () => import('@/views/dic/dic_info'),
        meta: { title: '字典管理' }
      },
      {
        path: 'sys_product',
        name: 'sys_product',
        component: () => import('@/views/sys_product/sys_product'),
        meta: { title: '系统产品' }
      },
    ]
  },
  {
    path: '/channel',
    component: Layout,
    name: 'channel',
    meta: { title: '渠道管理', icon: 'el-icon-data-board' },
    children: [
      {
        path: 'up_channel_info',
        name: 'up_channel_info',
        component: () => import('@/views/up_channel/up_channel_info'),
        meta: { title: '上游渠道' }
      },
      {
        path: 'up_channel_product',
        name: 'up_channel_product',
        component: () => import('@/views/up_channel/up_channel_product'),
        meta: { title: '上游产品' }
      },
      {
        path: 'down_channel_info',
        name: 'down_channel_info',
        component: () => import('@/views/down_channel/down_channel_info'),
        meta: { title: '下游渠道' }
      },
      {
        path: 'down_channel_product',
        name: 'down_channel_product',
        component: () => import('@/views/down_channel/down_channel_product'),
        meta: { title: '下游产品' }
      },
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router
